'use strict';
module.exports = {
	/**
	 * 添加配置
	 * @url admin/system_config/sys/add 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		let { type } = data;
					
		let dbName = "db-config";
		
		let dataJson = data;
		
		let whereJson = {};
		
		if(type) {
			whereJson["type"] = type;
		}
		
		// 执行数据库API请求
		res.data = await vk.baseDao.findByWhereJson({
			dbName,
			whereJson
		});
		
		if(!res.data) {
			res.data = await vk.baseDao.add({
				dbName,
				dataJson
			});
		} else {
			res.data = await vk.baseDao.updateById({
				dbName,
				id: res.data._id,
				dataJson
			})
		}
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
